var config = require('../config.js')
// const config = {
//   configUrl: "https://wanju.zzxkeji.cn/Api/"
// }
function Post(url, data, cb) {
  if(data==''){
    data={};
  }
  data.mchid = 'd072f71878ca8a3288b05bb50c0ecc65';
  wx.showNavigationBarLoading();
  wx.request({
    method: 'POST',
    url: config.HTTP_BASE_URL + url,
    data: data,
    success: (res) => {
      typeof cb == "function" && cb(res.data, "");
      wx.hideNavigationBarLoading();
    },
    fail: (err) => {
      typeof cb == "function" && cb(null, err.errMsg);
      wx.hideNavigationBarLoading();
    }
  });
};

function loading(e, t, n) {
  wx.showLoading({ mask: !0, title: e || "loading...", success: n })
}

function hideloading() {
  var e = setTimeout(function () {
    wx.hideLoading()
  }, 1e3)
}


function getCountDown(timestamp,cb) {
  setInterval(function () {
    var nowTime = new Date();
    var endTime = new Date(timestamp * 1000);

    var t = endTime.getTime() - nowTime.getTime();
    //            var d=Math.floor(t/1000/60/60/24);
    var hour = Math.floor(t / 1000 / 60 / 60 % 24);
    var min = Math.floor(t / 1000 / 60 % 60);
    var sec = Math.floor(t / 1000 % 60);

    if (hour < 10) {
      hour = "0" + hour;
    }
    if (min < 10) {
      min = "0" + min;
    }
    if (sec < 10) {
      sec = "0" + sec;
    }
    var countDownTime = hour + ":" + min + ":" + sec;
    typeof cb == "function" && cb(countDownTime);
  }, 1000);
}

module.exports = {
  httpPost: Post,
  getCountDown
};